package org.lex.ftp.ui.prefs;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.lex.net.proxy.ProxyManager;
import org.lex.swing.prefs.CategoryAdapter;


public class NetworkProxyCategory extends CategoryAdapter {
	private JButton deleteButton;
	private JButton editButton;
	private JButton addButton;
	private JPanel controlPane;
	private JTable table;
	private JScrollPane scrollPane;
	// -----------------------------
	private ProxyManager tableModel = new ProxyManager();

	public NetworkProxyCategory() {
		super();
		initialize();
	}

	private JTable getTable() {
		if (table == null) {
			table = new JTable(tableModel);
		}
		return table;
	}

	private void initialize() {
		setLayout(new BorderLayout());
		add(getScrollPane(), BorderLayout.CENTER);
		add(getControlPane(), BorderLayout.SOUTH);
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}

	private JPanel getControlPane() {
		if (controlPane == null) {
			controlPane = new JPanel();
			final FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(FlowLayout.TRAILING);
			flowLayout.setHgap(12);
			flowLayout.setVgap(6);
			controlPane.setLayout(flowLayout);
			controlPane.add(getAddButton());
			controlPane.add(getEditButton());
			controlPane.add(getDeleteButton());
		}
		return controlPane;
	}

	/**
	 * @return
	 */
	private JButton getAddButton() {
		if (addButton == null) {
			addButton = new JButton();
			addButton.setText("Add");
		}
		return addButton;
	}

	/**
	 * @return
	 */
	private JButton getEditButton() {
		if (editButton == null) {
			editButton = new JButton();
			editButton.setText("Edit");
		}
		return editButton;
	}

	/**
	 * @return
	 */
	private JButton getDeleteButton() {
		if (deleteButton == null) {
			deleteButton = new JButton();
			deleteButton.setText("Delete");
		}
		return deleteButton;
	}
}
